home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / ckadr / ckadr.c next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.9 KB  |  189 lines

  1. /* adr_check.c: check command line argument is a valid address */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/ckadr/RCS/ckadr.c,v 6.0 1991/12/18 20:28:46 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/ckadr/RCS/ckadr.c,v 6.0 1991/12/18 20:28:46 jpo Rel $
  9.  *
  10.  * $Log: ckadr.c,v $
  11.  * Revision 6.0  1991/12/18  20:28:46  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "adr.h"
  20. #include "retcode.h"
  21. #include "list_rchan.h"
  22.  
  23. static int    responsibility = YES;
  24. #ifdef UKORDER
  25. static int    dmnorder = CH_UK_PREF;
  26. #else
  27. static int    dmnorder = CH_USA_ONLY;
  28. #endif
  29. static void    parse_address();
  30. static int     ad_type = AD_822_TYPE;
  31. static int    percents = FALSE;
  32. static int    normalised = APARSE_NORM_NEXTHOP;
  33. static int    full = NOTOK;
  34. static int    adno = 1;
  35. /* ---------------------  Begin  Routines  ---------------------------------- */
  36.  
  37.  
  38. extern ADDR *adr_new_new();
  39.  
  40. main(argc, argv)
  41. int       argc;
  42. char       **argv;
  43. {
  44.     char    buf[BUFSIZ];
  45.     CHAN    *inchan;
  46.     extern int     optind;
  47.     extern char    *optarg;
  48.     int    opt;
  49.     ad_type = AD_822_TYPE;
  50.  
  51.     sys_init(argv[0]);
  52.     while ((opt = getopt (argc, argv, "ofrxanpbl0123i:")) != EOF)
  53.         switch (opt) {
  54.             case 'o':
  55.             /* originator address */
  56.             adno = 0;
  57.             break;
  58.             case 'i':
  59.             /* inbound channel to set addressing */
  60.             if ((inchan = ch_nm2struct (optarg)) == NULLCHAN) {
  61.                 printf("Unknown channel '%s'\n",
  62.                        optarg);
  63.                 exit(1);
  64.             }
  65.             if (inchan -> ch_chan_type != CH_IN
  66.                 && inchan -> ch_chan_type != CH_BOTH) {
  67.                 printf("Channel '%s' is not an inbound channel\n",
  68.                        inchan -> ch_name);
  69.                 exit (1);
  70.             }
  71.             ad_type = inchan -> ch_in_ad_type;
  72.             dmnorder = inchan -> ch_ad_order;
  73.  
  74.             if (inchan -> ch_in_ad_subtype == AD_JNT
  75.                 || inchan -> ch_in_ad_subtype == AD_REAL733)
  76.                 percents = TRUE;
  77.  
  78.             if (inchan -> ch_domain_norm == CH_DOMAIN_NORM_ALL)
  79.                 normalised = APARSE_NORM_ALL;
  80.                 
  81.             case 'f':
  82.             full = OK;
  83.             break;
  84.  
  85.             case 'r':
  86.             ad_type = AD_822_TYPE;
  87.             break;
  88.  
  89.             case 'x':
  90.             ad_type = AD_X400_TYPE;
  91.             break;
  92.                 
  93.             case 'a':
  94.             normalised = APARSE_NORM_ALL;
  95.             break;
  96.             case 'n':
  97.             responsibility = NO;
  98.             break;
  99.             case 'p':
  100.             percents = TRUE;
  101.             break;
  102.             case 'l':
  103.             dmnorder = CH_USA_PREF;
  104.             break;
  105.             case 'b':
  106.             dmnorder = CH_UK_PREF;
  107.             break;
  108.             case '0':
  109.             case '1':
  110.             case '2':
  111.             case '3':
  112.             dmnorder = opt - '0';
  113.             break;
  114.             default:
  115.             printf("usage: %s [-i inboundChan] [-x] [-r] [-a] [-n] [-p] [-b] [-o] [-l] [-0] [-1] [-2] [-3]\n", argv[0]);
  116.             exit(1);
  117.             break;
  118.         }
  119.     argc -= optind;
  120.     argv += optind;
  121.             
  122.     if (argc == 0) 
  123.         while (gets(buf) != NULL)
  124.             parse_address(buf);
  125.     else 
  126.         while (argc--)
  127.             parse_address(*argv++);
  128. }
  129.  
  130.  
  131.  
  132.  
  133. static void parse_address(str)
  134. char    *str;
  135. {
  136.     ADDR        *ad;
  137.     RP_Buf        rp;
  138.     int        origType;
  139.     int        first, retval;
  140.     LIST_RCHAN    *ix;
  141.  
  142.     ad = adr_new(str, ad_type, adno);
  143.     ad -> ad_resp = responsibility;
  144.     origType = ad->ad_type;
  145.     ad -> aparse -> percents = percents;
  146.     ad -> aparse -> normalised = normalised;
  147.     ad -> aparse -> dmnorder = dmnorder;
  148.     ad -> aparse -> full = full;
  149.  
  150.     if (rp_isbad(retval = ad_parse_aux(ad, &rp)))
  151.         printf("Address parsing failed:\nReason: %s\nParsing gave this:\n\n", ad->ad_parse_message);
  152.         
  153.  
  154.  
  155.  
  156.     if (ad->ad_type == AD_X400_TYPE) {
  157.         if (isstr(ad->ad_r400adr))
  158.             printf("%s ->  (x400)  %s\n", str, ad->ad_r400adr);
  159.  
  160.         if (isstr(ad->ad_r822adr))
  161.             printf("%s -> (rfc822) %s\n", str, ad->ad_r822adr);
  162.     } 
  163.     else {
  164.         if (isstr(ad->ad_r822adr))
  165.             printf("%s -> (rfc822) %s\n", str, ad->ad_r822adr);
  166.  
  167.         if (isstr(ad->ad_r400adr))
  168.             printf("%s ->  (x400)  %s\n", str, ad->ad_r400adr);
  169.     }
  170.  
  171.     ix = ad -> ad_outchan;
  172.     first = 0;
  173.  
  174.     if (!rp_isbad(retval)) {
  175.         while (ix) {
  176.             if (first == 0)
  177.                 printf ("\n");
  178.  
  179.             printf("%s to %s by %s\n",
  180.                    (first++ == 0) ? "Delivered" : "Or delivered",
  181.                    ix  -> li_mta,
  182.                    (ix -> li_chan) ? 
  183.                    ix -> li_chan -> ch_name : "no channel given");
  184.             ix = ix -> li_next;
  185.         }
  186.     }
  187.     printf ("\n");
  188. }
  189.